home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / shells / guest-0.000 / guest-0 / guest-0.2 / string.c < prev    next >
C/C++ Source or Header  |  1995-05-08  |  2KB  |  56 lines

  1. /*
  2. Manipulates strings for easier parsing
  3. Copyright (C) 1995  Brian Cully
  4.  
  5. This program is free software; you can redistribute it and/or modify it under
  6. the terms of the GNU General Public License as published by the Free Software
  7. Foundation; either version 2 of the License, or (at your option) any later
  8. version.
  9.  
  10. This program is distributed in the hope that it will be useful, but WITHOUT
  11. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  12. FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  13. details.
  14.  
  15. You should have received a copy of the GNU General Public License along with
  16. this program; if not, write to the Free Software Foundation, Inc., 675 Mass
  17. Ave, Cambridge, MA 02139, USA.
  18.  
  19. please send patches or advice to: `shmit@meathook.intac.com'
  20. */
  21.  
  22. #include <string.h>
  23. #include "string.h"
  24.  
  25. /* get a substring from a string, substrings are non-delimiter characters
  26. ** separated by delimiters
  27. ** On entry:
  28. **    src == source string
  29. **    dst == destination string
  30. **    delim == delimiter
  31. ** On exit:
  32. **    -1 if '\0' was found
  33. **    otherwise, index offset in src where dst ends
  34. */
  35.  
  36. int substr(const char *src, char *dst, char delim) {
  37.    int index=0;
  38.  
  39.    while ((*(src+index) != delim) && (*(src+index) != '\0')) {
  40.       *(dst+index) = *(src+index);
  41.       index++;
  42.    }
  43.    *(dst+index) = '\0';
  44.    if (*(src+index) != '\0')
  45.       return(index);
  46.    return(-1);
  47. }
  48.  
  49. int strwhite(const char *src) {
  50.    int i=0;
  51.    
  52.    while (*(src+i) == ' ')
  53.       i++;
  54.    return(i);
  55. }
  56.